package smartcounters.androidclient.model;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.ksoap2.serialization.SoapObject;

public class Fault {
    private int m_FaultID;
    private int m_UserID;
    private int m_AccountID;
    private Date m_FaultDate;
    private String m_Description;
    private boolean m_IsSolved;

    public Fault(int i_FaultID, int i_UserID)
    {
        m_FaultID = i_FaultID;
        m_UserID = i_UserID;
    }
    
    public static Fault CreateFromSoapObject(SoapObject faultObject){
    	DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	Fault fault = new Fault(Integer.parseInt(faultObject.getProperty("FaultID").toString()), Integer.parseInt(faultObject.getProperty("UserID").toString()));
		fault.setAccountID(Integer.parseInt(faultObject.getProperty("AccountID").toString()));
		try {
			fault.setFaultDate(format.parse(faultObject.getProperty("FaultDate").toString().replace('T', ' ')));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		fault.setDescription(faultObject.getProperty("Description").toString());
		fault.setIsSolved(Boolean.parseBoolean(faultObject.getProperty("IsSolved").toString()));
		
		return fault;
    }
    
    public int getFaultID(){
    	return m_FaultID;
    }
    
    public int getUserID(){
    	return m_UserID;
    }
    
    public int getAccountID(){
    	return m_AccountID;
    }
    
    public void setAccountID(int i_AccountID){
    	m_AccountID = i_AccountID;
    }
    
    public Date getFaultDate(){
    	return m_FaultDate;
    }
    
    public void setFaultDate(Date i_FaultDate){
    	m_FaultDate = i_FaultDate;
    }
    
    public String getDescription(){
    	return m_Description;
    }
    
    public void setDescription(String i_Description){
    	m_Description = i_Description;
    }
    
    public boolean getIsSolved(){
    	return m_IsSolved;
    }
    
    public void setIsSolved(boolean i_IsSolved){
    	m_IsSolved = i_IsSolved;
    }
}
